package com.pablosz.worm.components;

import com.pablosz.worm.util.Point;

public class ScoreStrategy
{
	private boolean readyToCompute = false;
	private int maxScore = 100;
	
	private int steepCount = 1;
	private Point fruitPossition = null;
	private Point wormPossition = null;
	private int steepSize;
	
	public ScoreStrategy()
	{
		fruitPossition = new Point();
		wormPossition = new Point();
	}
	
	public void setSteepSize(int s)
	{
		steepSize = s;
	}
	
	public void addSteep()
	{
		readyToCompute=true;
		steepCount++;
	}
	
	public void setFruitPossition(long x, long y)
	{
		if( !readyToCompute )
		{
			fruitPossition.x = x;
			fruitPossition.y = y;
		}
	}
	
	public void setWormPossition(long x, long y)
	{
		if( !readyToCompute )
		{
			wormPossition.x = x;
			wormPossition.y = y;
		}
	}
	
	public long compute()
	{
		readyToCompute=false;
		
		// cantidad mimina de pasos
		long optimo = (long)Math.abs(wormPossition.x-fruitPossition.x);
		optimo+=(long)Math.abs(wormPossition.y-fruitPossition.y);
		optimo = optimo/steepSize;
		
		double porc = optimo*100/steepCount;
		
		steepCount = 1;
		
		return (long)(porc*100/maxScore);
	}
	
}
